package com.bjpowernode.springsecurity01.controller;


import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.CircleCaptcha;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import javax.imageio.ImageIO;
import java.io.IOException;

@Controller
public class CaptchaController {

    @GetMapping("/code/image")
    private void code(HttpServletRequest request, HttpServletResponse response) throws IOException {
        CircleCaptcha circleCaptcha = CaptchaUtil.createCircleCaptcha(200, 100, 2, 4);

        request.getSession().setAttribute("code", circleCaptcha.getCode());

        ImageIO.write(circleCaptcha.getImage(),"png",response.getOutputStream());
    }
}
